package com.rongshu.sendmessage.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.rongshu.sendmessage.R;
import com.rongshu.sendmessage.base.BaseActivity;
import com.rongshu.sendmessage.base.MyApplication;
import com.rongshu.sendmessage.view.TitileLayout;

public class WebYinSiActivity extends BaseActivity {
    private WebView webView;
    private String yinsixieyi;
    private String souce;
    private TitileLayout tl_title;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web_yin_si);
        mContext = this;
        initView();
        initWebUrl();
    }

    private void initView() {
        webView = findViewById(R.id.webView);
        tl_title = findViewById(R.id.tl_title);
        tl_title.hideRight();
        tl_title.setTitleClickListener(new TitileLayout.TitleClickListenerA() {
            @Override
            public void onLeftClick() {
                finish();
            }
        });
        webView.getSettings().setDefaultTextEncodingName("UTF-8");
        Log.e("=======", "-----------------------------" + getPackageName());
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                // TODO Auto-generated method stub
                handler.proceed();// 接受所有网站的证书
            }
        });
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);//允许使用js
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);//不使用缓存，只从网络获取数据.
        webSettings.setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        souce = getIntent().getStringExtra("souce");
        if ("yinsi".equals(souce)) {
            tl_title.setTitle("隐私政策");
        } else {
            tl_title.setTitle("服务协议");
        }
    }

    private void initWebUrl() {
        if ("yinsi".equals(souce)) {
            webView.loadUrl("http://www.kyxxylzx.com/tckx/privacyAgreement.html");
        } else {
            webView.loadUrl("http://www.kyxxylzx.com/tckx/userAgreement.html");
        }
    }
}